package vip.geeker.iotms.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import vip.geeker.iotms.help.Constants;
import vip.geeker.iotms.help.Response;
import vip.geeker.iotms.service.impl.DeviceTypeDataService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/data")
public class DataRealTimeController {

    @Resource
    private DeviceTypeDataService deviceTypeDataService;

    @GetMapping("/toDataTypePage")
    public String toDataTypePage(HttpServletRequest request) {
//        deviceTypeDataService.selectDeviceByData("湿度");
        List<String> list = deviceTypeDataService.queryGroupData();
        request.setAttribute("dataGroup",list);
        return Constants.DATA_TYPE_LIST_PAGE_URL;
    }

    @GetMapping("/toPage")
    public String toPage(HttpServletRequest request,String dataName) {
        request.setAttribute("dataName",dataName);
        return Constants.DATA_LIST_PAGE_URL;
    }

    @GetMapping("/qyeryDeviceInfo")
    @ResponseBody
    public Object queyData(int pageNo,int pageSz,String dataName) {
        return deviceTypeDataService.selectDeviceByData(pageNo,pageSz,dataName);
    }

    @GetMapping("/group")
    @ResponseBody
    public Object getDeviceDataGroup() {
        return deviceTypeDataService.queryGroupData();
    }

    @GetMapping("/realDataPage")
    public String topRealDataPage(HttpServletRequest request,
                                  String name,String no,String typeName,String location,String dataName) {
        request.setAttribute("name",name);
        request.setAttribute("no",no);
        request.setAttribute("typeName",typeName);
        request.setAttribute("location",location);
        request.setAttribute("dataName",dataName);
        return Constants.DATA_REAL_PAGE_URL;
    }
}
